package com.quanfaqiang.demo1.controller;


import com.quanfaqiang.demo1.pojo.Result;
import com.quanfaqiang.demo1.service.StatisticalAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

@RequestMapping("/StatisticalAnalysis")
@RestController
public class StatisticalAnalysisContriller {

    @Autowired
    private StatisticalAnalysisService statisticalAnalysisService;



    @GetMapping("/SelectAll")
    public Result SelectAll() {
        HashMap<String, Long> counts = statisticalAnalysisService.SelectAll();
        return Result.success(counts);
    }



//    @Autowired
//    private UserRepository userRepository;
//
//    // 获取昨天和今天的新增用户数量
//    @GetMapping("/daily-count")
//    public Result getDailyUserCount() {
//        Map<String, Object> result = new HashMap<>();
//
//        // 获取昨天和今天的新增用户数量
//        LocalDateTime yesterday = LocalDateTime.now().minusDays(1).truncatedTo(ChronoUnit.DAYS);
//        LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
//
//        // 昨天新增用户数量
//        Long yesterdayCount = userRepository.countByAddTimeBetween(yesterday, yesterday.plusDays(1));
//
//        // 今天新增用户数量
//        Long todayCount = userRepository.countByAddTimeBetween(today, today.plusDays(1));
//
//        result.put("yesterday", yesterdayCount);
//        result.put("today", todayCount);
//
//        return Result.success(result);
//    }



    @GetMapping("/UserCount")
    public Result UserCount() {
        TreeMap<LocalDate, Long> counts = statisticalAnalysisService.UserCount();
        return Result.success(counts);
    }
}


